/**
 * 标准列表
 * @author linfeng
 * @since 2019/12/24
 */
layui.extend({
    zmnExportUtil: '{/}/static/js/zmn.excel.util'
}).define(['index', 'form', 'table', 'laypage', 'layedit','zmnExportUtil','laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    let layDate = layui.laydate;
    var layedit = layui.layedit;
    var zmnExportUtil =layui.zmnExportUtil;

    layDate.render({
        elem: '#startAndEndDate',
        range: true
    });

    form.render();

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        defaultToolbar: ['exports'],
        limit: json.pageSize,
        height: 'full-149',
        done: function () {
            $("div[lay-event='LAYTABLE_EXPORT']").attr('lay-event', 'CUSTOM_EXPORT');
        },
    });

    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    var ids = new Array();

    // 表格复选框监听
    table.on("checkbox(zmn-table)", function () {
        ids = table.checkStatus('zmn-table').data.map((item) => item.channelId);
    });

    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event == 'add') {
            if (ids.length === 0) {
                return layer.alert("请选择至少一条数据！");
            }
            layer.confirm('注意：如果原渠道已有价格表会被替换成新的价格表', {
                btn: ['确定', '取消']
            }, function () {
                let url= "/channel/tariff/add.action";
                let data ={ids: ids.join(","), tariffId:json.vo.tariffId};
                $.ajax({
                    type: "POST", url: url,
                    dataType: "json", data: data,
                    success: function (json) {
                        if (json.status == 200) {
                            zmnPage.reload(json.message, 1000,function () {
                                let index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                        } else {
                            layer.msg(json.message);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                    }
                });
            });
            return false;
        }
    });


    //对外暴露的接口
    exports('channel_tariff_select_list_js', {});
});

